

'''
最坏复杂度：O(n^2)
最好复杂度：O(n)
稳定性：稳定
'''
def bubble_sort(nums):

    for i in range(len(nums)-1):
        flag = False
        for j in range(i+1,len(nums)):
            if nums[i] > nums[j]:
                nums[i],nums[j] = nums[j],nums[i]
                flag = True
        if not flag:
            break
nums = [5,4,3,2,1]
bubble_sort(nums)
print(nums)